package com.ruoyi.tjfx.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.hutool.core.collection.CollUtil;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.tjfx.domain.ReportMonthlyBo;
import com.ruoyi.tjfx.domain.ReportMonthlyVo;
import com.ruoyi.tjfx.service.ReportMonthlyService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 试验月报
 *
 * @author zxs
 * @date 2024-09-03
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/monthlyReport")
public class ReportMonthlyController extends BaseController {

    private final ReportMonthlyService service;


    /**
     * 查询试验月报
     */
    @SaCheckLogin
    @GetMapping("/monthlyReport")
    public TableDataInfo taiZhang(@Validated(QueryGroup.class) ReportMonthlyBo bo) {
        return service.monthlyReport(bo);
    }


    /**
     * 导出月报数据
     */
    @PostMapping("/exportMonthlyReport")
    public void exportMonthlyReport(HttpServletResponse response, ReportMonthlyBo bo) {
        List<ReportMonthlyVo> list = service.monthlyReport(bo).getRows();
        Map<String, String> map = new HashMap<>();
        ExcelUtil.exportTemplate(CollUtil.newArrayList(map, list), "试验月报.xlsx", "excel/试验月报.xlsx", response);
    }

}
